package com.giscloud.generator.controller;

import com.giscloud.generator.entity.vo.UserIdentityVO;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @Author:giscloud
 * @Description:
 * @Date: 17:09 2018/3/7
 * @Modified By:
 */
public class BaseController extends com.giscloud.commons.base.BaseController {

    /**
     * 获取getRequest
     * @return
     */
    public HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public HttpServletResponse getResponse() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
    }
    /**
     * 获取登录用户信息
     *
     * @return
     */
    public UserIdentityVO getLoginUser() {
        UserIdentityVO userVO = (UserIdentityVO) getRequest().getAttribute("userVO");
        return userVO != null ? userVO : null;
    }

    /**
     * 获取登录用户ID
     *
     * @return
     */
    public long getUserId() {
        UserIdentityVO userVO = (UserIdentityVO) getRequest().getAttribute("userVO");
        return userVO != null ? userVO.getId() : null;
    }
}
